package handler

import (
	"rdiot-demo/internal/eav/eav_service"

	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

// RegisterRoutes 注册EAV模块路由
func RegisterRoutes(router *gin.RouterGroup, eavServices *eav_service.EAVServices, logger *zap.Logger) {
	api := NewAPI(eavServices, logger)

	// EAV API group
	eavGroup := router.Group("/eav")
	{
		// 模板管理路由
		templatesGroup := eavGroup.Group("/templates")
		{
			templatesGroup.POST("", api.TemplateAPI.CreateTemplate)       // POST /api/v1/eav/templates
			templatesGroup.GET("", api.TemplateAPI.ListTemplates)         // GET /api/v1/eav/templates
			templatesGroup.GET("/:id", api.TemplateAPI.GetTemplate)       // GET /api/v1/eav/templates/{id}
			templatesGroup.PUT("/:id", api.TemplateAPI.UpdateTemplate)    // PUT /api/v1/eav/templates/{id}
			templatesGroup.DELETE("/:id", api.TemplateAPI.DeleteTemplate) // DELETE /api/v1/eav/templates/{id}

			// 根据模板获取实体
			templatesGroup.GET("/:templateId/entities", api.EntityAPI.GetEntitiesByTemplate) // GET /api/v1/eav/templates/{templateId}/entities
		}

		// 实体管理路由
		entitiesGroup := eavGroup.Group("/entities")
		{
			entitiesGroup.POST("", api.EntityAPI.CreateEntity)                          // POST /api/v1/eav/entities
			entitiesGroup.POST("/batch", api.EntityAPI.BatchCreateEntities)             // POST /api/v1/eav/entities/batch
			entitiesGroup.POST("/query", api.EntityAPI.QueryEntities)                   // POST /api/v1/eav/entities/query
			entitiesGroup.GET("/:id", api.EntityAPI.GetEntity)                          // GET /api/v1/eav/entities/{id}
			entitiesGroup.GET("/:id/attributes", api.EntityAPI.GetEntityWithAttributes) // GET /api/v1/eav/entities/{id}/attributes
			entitiesGroup.PUT("/:id", api.EntityAPI.UpdateEntity)                       // PUT /api/v1/eav/entities/{id}
			entitiesGroup.DELETE("/:id", api.EntityAPI.DeleteEntity)                    // DELETE /api/v1/eav/entities/{id}
		}
	}
}

// RegisterHealthRoutes 注册健康检查路由
func RegisterHealthRoutes(router *gin.RouterGroup, eavServices *eav_service.EAVServices, logger *zap.Logger) {
	healthGroup := router.Group("/health")
	{
		healthGroup.GET("/eav", func(c *gin.Context) {
			// 简单的健康检查
			c.JSON(200, gin.H{
				"service":   "eav",
				"status":    "healthy",
				"timestamp": "2025-06-19T10:30:00Z",
			})
		})
	}
}
